package com.kang.controller;

import com.github.pagehelper.PageInfo;
import com.kang.bean.Role;
import com.kang.commons.Result;
import com.kang.service.RoleService;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @program: service
 * @description:
 * @author: K.faWu
 * @create: 2022-02-28 13:24
 **/
@RestController
@RequestMapping("role")
public class RoleController {
    private final RoleService roleService;

    public RoleController(RoleService roleService) {
        this.roleService = roleService;
    }

    @PostMapping("/delete")
    public Result<?> delete(@RequestBody List<Role> list){
        roleService.delete(list);
        return Result.success();
    }

    @PutMapping
    public Result<?> add(@RequestBody Role role){
        roleService.save(role);
        return Result.success();
    }

    @PostMapping
    public Result<?> update(@RequestBody Role role){
        roleService.updateById(role);
        return Result.success();
    }

    @PostMapping("/getList")
    public Result<?> getList(@RequestBody Role role, Pageable page, HttpServletRequest request){
        PageInfo<Role> pageInfo = roleService.getList(role, page, request);
        return Result.success(pageInfo);
    }

}
